﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class MainForm : Form
    {
        // T/F value - keeps track of whether or not more advanced visual effects are turned on.
        bool FancyBars = false;

        // Set up Pen to draw rectangles
        Pen GreyPen = new Pen(Color.LightGray, 1);

        // Set coloured brushes for filling rectangles
        SolidBrush b1 = new SolidBrush(Color.Blue);
        SolidBrush b2 = new SolidBrush(Color.LightGray);
        SolidBrush b3 = new SolidBrush(Color.Red);
        SolidBrush b4 = new SolidBrush(Color.Green);
        SolidBrush b5 = new SolidBrush(Color.White);
        SolidBrush fancyb1 = new SolidBrush(Color.MidnightBlue);
        SolidBrush fancyb2 = new SolidBrush(Color.MediumVioletRed);
        SolidBrush fancyb3 = new SolidBrush(Color.MediumSeaGreen);

        // Tells program that a non-default imagepack setting is being used.
        bool impackURLmodified = false;

        // Holds image pack path, to append to start of the calcualted image name string.
        string imagePackPath;

        public MainForm()
        {
            InitializeComponent();
        }

        // Ship Data Array
        private int[,] ShipData()
        {
            // Format:  {missile mounts, gun mounts, hull cap, size, armor, hull, class(coin), req. xp/rank, price, crew seats}
            // Faction/Syndicate ranks are 1.~ feds, 2.~ emps etc.
            int[,] shipData = { 
                              {0,1,70,12,225,195, 5, 0, 15000,0}, /* 0. Sabre */
                              {0,1,105,63,135,240, 6, 645, 21500,0 },/* 1.Rustclaw */
                              {1, 3, 85, 8, 285, 165, 0, 2220, 74000, 0}, /* 2. Interceptor */
                              { 0, 0, 180, 45, 300, 270, 6, 11460, 382000, 1}, /* 3. Lanner Mini */
                              {4,2,165,56,210,375,4,12600,420000,1}, /* 4. Harrier */
                              {3,3,120,27,390,210,1,25560,426000,1}, /* 5. Mercury */
                              {10,2,255,66,195,525,5,79200,1320000,2}, /* 6. Hercules */
                              {0,0,285,98,390,375,6,94500,1575000,2}, /* 7. Lanner */
                              {0,5,150,33,480,225,0,102000,1700000,1}, /* 8. Hawk */
                              {6,4,195,79,450,450,2,177000,2950000,2}, /* 9. Gargantua */
                              {8,2,315,206,405,720,6,299700,4995000,3}, /* 10. BBB */
                              {8,4,240,82,510,525,2,509850,16995000,3}, /* 11. Liberator */
                              {0,2,75,14,240,225,2,11,20000,0}, /* 12. Wasp */
                              {2,1,100,18,255,285,5,12,35000,0}, /* 13. Adder */
                              {3,2,125,29,270,360,4,13,121000,1}, /* 14. Thunderbird */
                              {2,3,95,10,405,300,0,14,183000,0}, /* 15. Viper Defence Craft */
                              {6,2,225,92,210,525,6,16,532000,2}, /* 16. Babel Transporter */
                              {0,4,130,24,375,315,0,16,566000,0}, /* 17. Piranha */
                              {1,4,165,29,510,270,0,18,2000000,1}, /* 18. Nighthawk */
                              {3,4,175,36,540,300,0,19,3000000,2}, /* 19. Nighthawk Deluxe */
                              {8,3,250,134,390,600,4,19,3300000,2}, /* 20. Mantis */
                              {14,2,310,104,345,750,6,110,4100000,2}, /* 21. Extender */
                              {7,4,220,68,585,465,0,111,8900000,2}, /* 22. Gauntlet */
                              {10,5,265,101,720,585,1,113,34750000,3}, /* 23. Doomstar */
                              {25,5,290,250,990,810,1,114,105000000,4}, /* 24. War Nova */
                              {0,2,80,17,270,210,2,21,21000,0}, /* 25. Ficon */
                              {3,0,130,74,60,300,6,22,38500,1}, /* 26. Tyrant */
                              {2,2,135,34,225,330,5,23,190000,0}, /* 27. Spectre */
                              {0,4,95,7,405,90,0,24,310000,0}, /* 28. Shadow Stealth Craft */
                              {4,3,160,46,375,375,2,25,964000,1}, /* 29. Venom. */
                              {8,2,260,131,285,570,6,27,1500000,2}, /* 30. Constrictor */
                              {2,4,155,23,525,150,0,29,2720000,1}, /* 31. Phantom Advanced Stealth Craft */
                              {6,4,210,88,495,570,1,210,3650000,2}, /* 32. Dominator */
                              {12,2,330,182,465,795,6,211,8250000,2}, /* 33. Boa UC */
                              {16,4,325,142,540,945,3,213,37900000,4}, /* 34. Mooncrusher */
                              {1,2,100,60,210,255,4,32,32500,0}, /* 35. Rustfire */
                              {0,3,105,14,330,120,0,34,200000,0}, /* 36. Marauder */
                              {2,1,210,52,90,540,6,35,780000,0}, /* 37. Junker IV */
                              {2,3,180,38,285,330,3,36,1330000,1}, /* 38. Slider */
                              {6,2,270,140,195,510,6,37,1650000,2}, /* 39. Elpadre */
                              {4,4,175,46,420,240,1,38,2310000,1}, /* 40. Chitin */
                              {0,4,255,78,390,420,2,310,5050000,2}, /* 41. Horpor */
                              {6,4,235,84,630,525,1,312,15125000,3}, /* 42. Scorpion */
                              {6,3,125,20,420,120,1,46,600000,0}, /* 43. Rover */
                              {8,4,160,50,495,185,0,49,1960000,1}, /* 44. Reaper */
                              {11,3,235,98,390,270,3,410,3125000,2}, /* 45. Blood Lanner */
                              {5,5,195,75,600,300,0,412,15000000,3}, /* 46. Sudden Death */
                              {2,4,140,26,330,510,1,57,990000,1}, /* 47. Trident */
                              {4,1,290,88,360,450,6,510,2500000,2}, /* 48. Celeus */
                              {4,3,210,30,405,600,2,511,6700000,2}, /* 49. Vulcan */
                              {8,4,255,85,540,540,2,513,18050000,4}, /* 50. Liberator EPS */
                              };
            return shipData;
        } // End of ship data tables.

        // Gun Data Array
        private int[,] GetGunData()
        {
            // Format: {damage, fire-rate, weight, cost, rank} a zero indicates N/A.
            // Lucidi Weapons have a unique ID because of their crystal requirement -
            // Lucidi Enforcer I = 200k + 8 crystals.
            // Lucidi Enforcer II = 400k + 14 crystals.
            // Lucidi Conqueror = 800k + 32.
            // Lucidi Plasma Thrower = 1.6mil + 40 crystals.
            int[,] gunData = {
                                 {0,0,0,0,0}, /* 0. :: None :: */
                                 {6,1,4,1000,0}, /* 1. 10MW Mining Laser */
                                 {15,1,6,5000,0}, /* 2. 30MW Mining Laser */
                                 {21,1,2,12000,0}, /* 3. 1MW Impulse Laser */
                                 {30,1,3,28000,0}, /*4. 5MW Impulse Laser */
                                 {27,2,4,86000,0}, /*5. 1MW Particle */
                                 {42,2,8,210000,0}, /*6. 4MW Particle */
                                 {42,2,5,510000,0}, /*7. 4MW LW Particle */
                                 {60,2,14,550000,0}, /*8. 20MW Particle */
                                 {60,2,10,925000,0}, /*9. 20MW LW Particle */
                                 {84,2,30,980000,0}, /*10. 100MW Particle */
                                 {84,2,24,2000000,0}, /*11. 100MW LW Particle */
                                 {30,3,22,180000,23}, /*12. 4MW Gatling */
                                 {30,3,14,540000,27}, /*13. 4MW LW Gatling */
                                 {48,3,34,400000,25}, /*14. 6MW Gatling */
                                 {48,3,20,1200000,29}, /*15. 6MW LW Gatling */
                                 {69,3,50,720000,28}, /*16. 10MW Gatling */
                                 {69,3,30,2160000,212}, /*17. 10MW LW Gatling */
                                 {115,3,78,2200000,213}, /*18. 20MW Gatling */
                                 {115,3,60,6600000,214}, /*19. 20MW LW Gatling */
                                 {240,1,38,2280000,212}, /*20. 35MW Plasma */
                                 {270,1,42,2500000,213}, /*21. 40MW Plasma */
                                 {345,1,54,8250000,214}, /*22. 60MW Plasma */
                                 {102,2,36,1400000,210}, /*23. 140MW Particle */
                                 {102,2,28,2400000,211}, /*24. 140MW LW Particle */
                                 {36,2,4,580000,0}, /* 25. Exoplasm */
                                 {42,2,8,400000,0}, /* 26. Endoplasm */
                                 {42,3,16,850000,0}, /* 27. Bio-Spore Array */
                                 {78,2,28,1680000,0}, /* 28. Viral Glands */
                                 {39,2,6,650000,0}, /* 29. 80MT MagDef */
                                 {51,2,7,950000,0}, /* 30. 120 MT MagDef */
                                 {165,1,30,1980000,0}, /* 31. LPC */
                                 {210,1,40,2600000,0}, /* 32. VLPC */
                                 {40,2,8,1,0}, /* 33. Lucidi Enforcer I */
                                 {55,2,14,2,0}, /* 34. Lucidi Enforcer II */
                                 {150,1,34,3,0}, /*  35. Lucidi Conqueror */
                                 {90,2,56,4,0} /* 36. Lucidi Plasma Thrower */
                               };
            return gunData;
        }

        // Action when "close" button is pressed - form is closed.
        private void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void shipSelectBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Take the piss out of lanner pilots.
            if ((shipSelectBox.Text == "- Lanner") || (shipSelectBox.Text == "- Lanner Mini"))
            {
                gunzlabel.Text = "WTF No Guns?!?";
            }
            else
            {
                gunzlabel.Text = "Select Guns:";
            }

            // Ship specification variables.
            int missileMounts;
            int gunMounts;
            // int hullCapacity;
            int shipSize;
            int shipArmor;
            int shipHull;
            int shipPrice;
            //int previousHull;
            //int previousSize;
            //int previousArmor;

            // Array lookup modes:
            int modeMissileMounts = 0;
            int modeGunMounts = 1;
            // int modeHullCapacity = 2;
            int modeSize = 3;
            int modeArmor = 4;
            int modeHull = 5;
            //int modeClass = 6;
            // int modeXpRankRequirement = 7;
            int modeShipPrice = 8;
            // int modeCrewSeats = 9;

            // Get ship data from array:
            shipSize = GetShipData(ref modeSize);
            shipArmor = GetShipData(ref modeArmor);
            shipHull = GetShipData(ref modeHull);
            gunMounts = GetShipData(ref modeGunMounts);
            missileMounts = GetShipData(ref modeMissileMounts);
            shipPrice = GetShipData(ref modeShipPrice);

            // Add numerical values to complement info-bars:
            shipSizeNumericalLabel.Text = shipSize.ToString();
            hullPointsNumericalLabel.Text = shipHull.ToString();
            armorPointsNumericalLabel.Text = shipArmor.ToString();

            // Add Data to info-labels under ship selection:
            numberofMissileSlotsLabel.Text = missileMounts.ToString();
            shipPriceLabel.Text = shipPrice.ToString("N0");

            // Scale data values to fit bar as many are over "250"
            shipArmor = shipArmor / 4;
            shipHull = shipHull / 4;

            // Add ship before slow info-bars - doesn't work. VC# seems to draw the bars even before the threads have been set off in code - odd.
            // Note: This means you have to wait for the fancy bars to finish rendering before anything new comes up - incuding new ship selection/data
            shipImageBox.ImageLocation = ConstructShipImagePaths();

            // Draw ship stats info-bars.
            if (FancyBars == true)
            {
                // Sets off a new thread to draw the info-bars.
                Thread SizeBarThread = new Thread(new ParameterizedThreadStart(DrawShipSizeBar));
                SizeBarThread.Start(shipSize);

                // Keeps the program busy till the thread has complete
                // Note: Initial idea of the threads was to allow user to continue using the program while the bars were updated elsewhere
                //       It would appear this is not actually possible, as multiple threads drawing to one form causes crashes - even if to different objects.
                while (thread1returnvalueLabel.Text != "done")
                {
                    workingLabel.Text = "Setting: Size";
                }

                Thread HullBarThread = new Thread(new ParameterizedThreadStart(DrawShipHullBar));
                HullBarThread.Start(shipHull);

                while ((thread1returnvalueLabel.Text != "done") || (thread2returnvalueLabel.Text != "done"))
                {
                    workingLabel.Text = "Setting : Hull";
                }

                Thread ArmorBarThread = new Thread(new ParameterizedThreadStart(DrawShipArmorBar));
                ArmorBarThread.Start(shipArmor);


                while ((thread1returnvalueLabel.Text != "done") || (thread2returnvalueLabel.Text != "done") || (thread3returnvalueLabel.Text != "done"))
                {
                    workingLabel.Text = "Setting: Armor";
                }

                // The thread labels are hidden, and effectively act as a way of passing data back to the main thread from the spawned threads
                // allowing the program to know when a thread has been completed - this avoids the multiple threads running simultaneously errors.
                thread1returnvalueLabel.Text = " ";
                thread2returnvalueLabel.Text = " ";
                thread3returnvalueLabel.Text = " ";
                workingLabel.Text = "Done";
            }

            else
            {
                // Ordinary, fast and choppy graph drawing.
                DrawStandardShipSizeBar(ref shipSize);
                DrawStandardShipArmorBar(ref shipArmor);
                DrawStandardShipHullBar(ref shipHull);
            }


            // Get Gun Mounts - Enable appropriate number of boxes.
            if (gunMounts == 0)
            {
                gunLoadoutComboBox1.Enabled = false;
                gunLoadoutComboBox2.Enabled = false;
                gunLoadoutComboBox3.Enabled = false;
                gunLoadoutComboBox4.Enabled = false;
                gunLoadoutComboBox5.Enabled = false;
            }
            if (gunMounts == 1)
            {
                gunLoadoutComboBox1.Enabled = true;
                gunLoadoutComboBox2.Enabled = false;
                gunLoadoutComboBox3.Enabled = false;
                gunLoadoutComboBox4.Enabled = false;
                gunLoadoutComboBox5.Enabled = false;
            }
            if (gunMounts == 2)
            {
                gunLoadoutComboBox1.Enabled = true;
                gunLoadoutComboBox2.Enabled = true;
                gunLoadoutComboBox3.Enabled = false;
                gunLoadoutComboBox4.Enabled = false;
                gunLoadoutComboBox5.Enabled = false;
            }
            if (gunMounts == 3)
            {
                gunLoadoutComboBox1.Enabled = true;
                gunLoadoutComboBox2.Enabled = true;
                gunLoadoutComboBox3.Enabled = true;
                gunLoadoutComboBox4.Enabled = false;
                gunLoadoutComboBox5.Enabled = false;
            }
            if (gunMounts == 4)
            {
                gunLoadoutComboBox1.Enabled = true;
                gunLoadoutComboBox2.Enabled = true;
                gunLoadoutComboBox3.Enabled = true;
                gunLoadoutComboBox4.Enabled = true;
                gunLoadoutComboBox5.Enabled = false;
            }
            if (gunMounts == 5)
            {
                gunLoadoutComboBox1.Enabled = true;
                gunLoadoutComboBox2.Enabled = true;
                gunLoadoutComboBox3.Enabled = true;
                gunLoadoutComboBox4.Enabled = true;
                gunLoadoutComboBox5.Enabled = true;
            }
        }

        private void customIPCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // Show/Hide Non-default imagepack options as reqiested by user input
            if (customIPCheckBox.Checked == true)
            {
                customIPTextBox.Visible = true;
                imagePackComboBox.Visible = false;
            }

            // Show/Hide Non-default imagepack options as reqiested by user input
            else
            {
                imagePackComboBox.Visible = true;
                customIPTextBox.Visible = false;
            }
        }

        private void customIPTextBox_MouseClick(object sender, MouseEventArgs e)
        {
            // Delete text initially in the custom text box, so user can insert appropriate data.
            if (customIPTextBox.Text == "Custom Imagepack Path")
            {
                customIPTextBox.Text = "";
            }
            impackURLmodified = true;
        }

        private void imagePackComboBox_MouseClick(object sender, MouseEventArgs e)
        {
            // Let program know if a non-default IP setting is in use.
            impackURLmodified = true;
        }

        private int GetShipData(ref int mode)
        {
            int shipReturnData;
            int[,] tempshipData = ShipData();

            // Begin Ship-dependant ShipData array lookups.
            switch (shipSelectBox.Text)
            {
                case "":
                    shipReturnData = 0;
                    return shipReturnData;

                case " ":
                    shipReturnData = 0;
                    return shipReturnData;

                case "Neutral Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Sabre":
                    shipReturnData = tempshipData[0, mode];
                    return shipReturnData;

                case "- Rustclaw":
                    shipReturnData = tempshipData[1, mode];
                    return shipReturnData;

                case "- Interceptor":
                    shipReturnData = tempshipData[2, mode];
                    return shipReturnData;

                case "- Lanner Mini":
                    shipReturnData = tempshipData[3, mode];
                    return shipReturnData;

                case "- Harrier":
                    shipReturnData = tempshipData[4, mode];
                    return shipReturnData;

                case "- Mercury":
                    shipReturnData = tempshipData[5, mode];
                    return shipReturnData;

                case "- Hercules":
                    shipReturnData = tempshipData[6, mode];
                    return shipReturnData;

                case "- Lanner":
                    shipReturnData = tempshipData[7, mode];
                    return shipReturnData;

                case "- Hawk":
                    shipReturnData = tempshipData[8, mode];
                    return shipReturnData;

                case "- Gargantua":
                    shipReturnData = tempshipData[9, mode];
                    return shipReturnData;

                case "- Behemoth":
                    shipReturnData = tempshipData[10, mode];
                    return shipReturnData;

                case "- Liberator":
                    shipReturnData = tempshipData[11, mode];
                    return shipReturnData;

                case "Federation Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Wasp":
                    shipReturnData = tempshipData[12, mode];
                    return shipReturnData;

                case "- Adder":
                    shipReturnData = tempshipData[13, mode];
                    return shipReturnData;

                case "- Thunderbird":
                    shipReturnData = tempshipData[14, mode];
                    return shipReturnData;

                case "- Viper Defence Craft":
                    shipReturnData = tempshipData[15, mode];
                    return shipReturnData;

                case "- Babel Transporter":
                    shipReturnData = tempshipData[16, mode];
                    return shipReturnData;

                case "- Piranha":
                    shipReturnData = tempshipData[17, mode];
                    return shipReturnData;

                case "- Nighthawk":
                    shipReturnData = tempshipData[18, mode];
                    return shipReturnData;

                case "- Nighthawk Deluxe":
                    shipReturnData = tempshipData[19, mode];
                    return shipReturnData;

                case "- Mantis":
                    shipReturnData = tempshipData[20, mode];
                    return shipReturnData;

                case "- Extender":
                    shipReturnData = tempshipData[21, mode];
                    return shipReturnData;

                case "- Gauntlet":
                    shipReturnData = tempshipData[22, mode];
                    return shipReturnData;

                case "- Doomstar":
                    shipReturnData = tempshipData[23, mode];
                    return shipReturnData;

                case "- War Nova":
                    shipReturnData = tempshipData[24, mode];
                    return shipReturnData;

                case "Empire Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Ficon":
                    shipReturnData = tempshipData[25, mode];
                    return shipReturnData;

                case "- Tyrant":
                    shipReturnData = tempshipData[26, mode];
                    return shipReturnData;

                case "- Spectre":
                    shipReturnData = tempshipData[27, mode];
                    return shipReturnData;

                case "- Shadow Stealth Craft":
                    shipReturnData = tempshipData[28, mode];
                    return shipReturnData;

                case "- Venom":
                    shipReturnData = tempshipData[29, mode];
                    return shipReturnData;

                case "- Constrictor":
                    shipReturnData = tempshipData[30, mode];
                    return shipReturnData;

                case "- Phantom Advanced Stealth Craft":
                    shipReturnData = tempshipData[31, mode];
                    return shipReturnData;

                case "- Dominator":
                    shipReturnData = tempshipData[32, mode];
                    return shipReturnData;

                case "- Boa Ultimate Carrier":
                    shipReturnData = tempshipData[33, mode];
                    return shipReturnData;

                case "- Mooncrusher":
                    shipReturnData = tempshipData[34, mode];
                    return shipReturnData;

                case "Union Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Rustfire":
                    shipReturnData = tempshipData[35, mode];
                    return shipReturnData;

                case "- Marauder":
                    shipReturnData = tempshipData[36, mode];
                    return shipReturnData;

                case "- Junker IV":
                    shipReturnData = tempshipData[37, mode];
                    return shipReturnData;

                case "- Slider":
                    shipReturnData = tempshipData[38, mode];
                    return shipReturnData;

                case "- El Padre":
                    shipReturnData = tempshipData[39, mode];
                    return shipReturnData;

                case "- Chitin":
                    shipReturnData = tempshipData[40, mode];
                    return shipReturnData;

                case "- Horpor":
                    shipReturnData = tempshipData[41, mode];
                    return shipReturnData;

                case "- Scorpion":
                    shipReturnData = tempshipData[42, mode];
                    return shipReturnData;

                case "TSS Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Rover":
                    shipReturnData = tempshipData[43, mode];
                    return shipReturnData;

                case "- Reaper":
                    shipReturnData = tempshipData[44, mode];
                    return shipReturnData;

                case "- Blood Lanner":
                    shipReturnData = tempshipData[45, mode];
                    return shipReturnData;

                case "- Sudden Death":
                    shipReturnData = tempshipData[46, mode];
                    return shipReturnData;

                case "EPS Ships":
                    shipReturnData = 0;
                    return shipReturnData;

                case "- Trident":
                    shipReturnData = tempshipData[47, mode];
                    return shipReturnData;

                case "- Celeus":
                    shipReturnData = tempshipData[48, mode];
                    return shipReturnData;

                case "- Vulcan":
                    shipReturnData = tempshipData[49, mode];
                    return shipReturnData;

                case "- Liberator EPS":
                    shipReturnData = tempshipData[50, mode];
                    return shipReturnData;
            }
            return 0;
        } // End of GetShipData();

        private string ConstructShipImagePaths()
        {
            string shipImagePath;

            // Used to get rid of the "- " in front of each of the ship names - makes it easier to manage the picture box display.
            int startIndex = 0;
            int count = 2;

            // Used in the string replace function, takes out spaces - puts in underscores.
            string oldChar = " ";
            string newChar = "_";

            // Convert strings from the drop down list to a corresponding image name in an imagepack. e.g. "- Wasp" >> "wasp_big.png" 
            shipImagePath = String.Format("{0} big.png", shipSelectBox.Text);
            shipImagePath = shipImagePath.Replace(oldChar, newChar);
            shipImagePath = shipImagePath.Remove(startIndex, count);
            shipImagePath = shipImagePath.ToLower();

            //Add exceptions for badly labelled images
            if (shipImagePath == "el_padre_big.png")
            {
                shipImagePath = "elpadre_big.png";
            }
            if (shipImagePath == "junker_iv_big.png")
            {
                shipImagePath = "junkeriv_big.png";
            }

            // Displays no image on non-ship entries in the drop down list such as "TSS Ships".
            if ((shipImagePath == "_select_ship_::_big.png") || (shipImagePath == "ig.png") || (shipImagePath == "utral_ships_big.png") || (shipImagePath == "deration_ships_big.png") || (shipImagePath == "pire_ships_big.png") || (shipImagePath == "ion_ships_big.png") || (shipImagePath == "s_ships_big.png"))
            {
                shipImageBox.Visible = false;
            }

            else
            {
                shipImageBox.Visible = true;

                // If non-default image path is being used.
                if (impackURLmodified == true)
                {
                    // If non-preset imagepack path is being used.
                    if (customIPCheckBox.Checked == true)
                    {
                        // Get custom path from input box.
                        imagePackPath = customIPTextBox.Text;
                    }

                    // If presets are being used - get appropriate image path.
                    else
                    {
                        if (imagePackComboBox.Text == "Old Standard Images - Offline")
                        {
                            imagePackPath = "c:/pardus/images/";
                        }
                        if (imagePackComboBox.Text == "New HQ Images - Offline")
                        {
                            imagePackPath = "c:/pardus/images_standardhq/";
                        }
                        if (imagePackComboBox.Text == "Old Standard Images - Online")
                        {
                            imagePackPath = "http://static.pardus.at/images/";
                        }
                        if (imagePackComboBox.Text == "New HQ Images - Online")
                        {
                            imagePackPath = "http://static.pardus.at/img/stdhq/";
                        }
                    }
                }

                // Default image pack path.
                else
                {
                    imagePackPath = "c:/pardus/images_standardhq/";
                }

                // Concatenate all calculated image path information.
                shipImagePath = imagePackPath + "big/" + shipImagePath;
            }
            return shipImagePath;
        }  // End of ConstructShipImagePaths()

        private void imagePackComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Resets image to match user's new selection by grabbing a new image path.
            shipImageBox.ImageLocation = ConstructShipImagePaths();
        }

        private void customIPTextBox_TextChanged(object sender, EventArgs e)
        {
            // Resets image to match user's new selection by grabbing a new image path.
            shipImageBox.ImageLocation = ConstructShipImagePaths();
        }

        // Standard Info-bars:
        private void DrawStandardShipSizeBar(ref int shipSize)
        {
            Graphics drawShipSizeBar = tabPage1.CreateGraphics();
            drawShipSizeBar.FillRectangle(b5, 388, 237, 250, 10);
            drawShipSizeBar.FillRectangle(b1, 388, 237, shipSize, 10);
        }

        private void DrawStandardShipArmorBar(ref int shipArmor)
        {
            Graphics drawShipArmorBar = tabPage1.CreateGraphics();
            drawShipArmorBar.FillRectangle(b5, 388, 278, 250, 10);
            drawShipArmorBar.FillRectangle(b3, 388, 278, shipArmor, 10);
        }

        private void DrawStandardShipHullBar(ref int shipHull)
        {
            Graphics drawShipHullBar = tabPage1.CreateGraphics();
            drawShipHullBar.FillRectangle(b5, 388, 257, 250, 10);
            drawShipHullBar.FillRectangle(b4, 388, 257, shipHull, 10);
        }

        // Fancy infobars.
        public void DrawShipSizeBar(object ThreadParameterSize)
        {
            int smoothdraw = 0;
            int shipSize = (int)ThreadParameterSize;

            Graphics drawShipSizeBar = tabPage1.CreateGraphics();
            drawShipSizeBar.FillRectangle(b5, 388, 237, 250, 10);

            // Draws bars up to desired value smoothly from 0 -> desired value.
            while (smoothdraw != shipSize)
            {
                smoothdraw++;
                Thread.Sleep(1);
                drawShipSizeBar.FillRectangle(fancyb1, 388, 237, smoothdraw, 10);
            }

            // Return data from thread:
            thread1returnvalueLabel.Text = "done";
            drawShipSizeBar.FillRectangle(fancyb1, 388, 237, shipSize, 10);
        }

        public void DrawShipArmorBar(object ThreadParameterArmor)
        {
            int smoothdraw = 0;
            int shipArmor = (int)ThreadParameterArmor;

            Graphics drawShipArmorBar = tabPage1.CreateGraphics();
            drawShipArmorBar.FillRectangle(b5, 388, 278, 250, 10);

            if (FancyBars == true)
            {
                while (smoothdraw != shipArmor)
                {
                    smoothdraw++;
                    drawShipArmorBar.FillRectangle(b3, 388, 278, smoothdraw, 10);
                    Thread.Sleep(1);
                }
            }
            thread3returnvalueLabel.Text = "done";
            drawShipArmorBar.FillRectangle(b3, 388, 278, shipArmor, 10);
        }

        public void DrawShipHullBar(object ThreadParameterHull)
        {
            int smoothdraw = 0;
            int shipHull = (int)ThreadParameterHull;

            Graphics drawShipHullBar = tabPage1.CreateGraphics();
            drawShipHullBar.FillRectangle(b5, 388, 257, 250, 10);

            if (FancyBars == true)
            {
                while (smoothdraw != shipHull)
                {
                    smoothdraw++;
                    drawShipHullBar.FillRectangle(b4, 388, 257, smoothdraw, 10);
                    Thread.Sleep(1);
                }
            }
            thread2returnvalueLabel.Text = "done";
            drawShipHullBar.FillRectangle(b4, 388, 257, shipHull, 10);
        } // End of Fancy Bars

        // Copy-links.
        private void copyLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            // Fearsome Ship Calc - style links to copy gun data from box to box.
            if (gunLoadoutComboBox2.Enabled == true)
            {
                UpdateGun2();
                gunLoadoutComboBox2.Text = gunLoadoutComboBox1.Text;
            }

            if (gunLoadoutComboBox3.Enabled == true)
            {
                UpdateGun3();
                gunLoadoutComboBox3.Text = gunLoadoutComboBox1.Text;
            }

            if (gunLoadoutComboBox4.Enabled == true)
            {
                UpdateGun4();
                gunLoadoutComboBox4.Text = gunLoadoutComboBox1.Text;
            }

            if (gunLoadoutComboBox5.Enabled == true)
            {
                UpdateGun5();
                gunLoadoutComboBox5.Text = gunLoadoutComboBox1.Text;
            }
        }

        private void copyLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            if (gunLoadoutComboBox3.Enabled == true)
            {
                UpdateGun3();
                gunLoadoutComboBox3.Text = gunLoadoutComboBox2.Text;
            }

            if (gunLoadoutComboBox4.Enabled == true)
            {
                UpdateGun4();
                gunLoadoutComboBox4.Text = gunLoadoutComboBox2.Text;
            }

            if (gunLoadoutComboBox5.Enabled == true)
            {
                UpdateGun5();
                gunLoadoutComboBox5.Text = gunLoadoutComboBox2.Text;
            }

        }

        private void CopyLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {


            if (gunLoadoutComboBox4.Enabled == true)
            {
                UpdateGun4();
                gunLoadoutComboBox4.Text = gunLoadoutComboBox3.Text;
            }

            if (gunLoadoutComboBox5.Enabled == true)
            {
                UpdateGun5();
                gunLoadoutComboBox5.Text = gunLoadoutComboBox3.Text;
            }

        }

        private void CopyLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            if (gunLoadoutComboBox5.Enabled == true)
            {
                UpdateGun5();
                gunLoadoutComboBox5.Text = gunLoadoutComboBox4.Text;
            }
        } // End of Copy-links.

        // Function Selects a value from the array containing Gun data. Mode allows you to select which data to pull from the table.
        // Note - there is one "lookup table" such as this for each of the 5 gun boxes.
        private int GetGunData1(ref int mode)
        {
            int gunDatareturn;
            int[,] gunDataTemp = GetGunData();

            switch (gunLoadoutComboBox1.Text)
            {
                case ":: None ::":
                case ":: Normal Guns::":
                case ":: Empire Guns ::":
                case "":
                case " ":
                case ":: Organic ::":
                case ":: Electro-Magnetic ::":
                case ":: Pardus ::":
                    gunDatareturn = gunDataTemp[0, mode];
                    return gunDatareturn;

                case "10MW Mining Laser":
                    gunDatareturn = gunDataTemp[1, mode];
                    return gunDatareturn;

                case "30MW Mining Laser":
                    gunDatareturn = gunDataTemp[2, mode];
                    return gunDatareturn;

                case "1MW Impulse Laser":
                    gunDatareturn = gunDataTemp[3, mode];
                    return gunDatareturn;

                case "5MW Impulse Laser":
                    gunDatareturn = gunDataTemp[4, mode];
                    return gunDatareturn;

                case "1MW Particle Laser":
                    gunDatareturn = gunDataTemp[5, mode];
                    return gunDatareturn;

                case "4MW Particle Laser":
                    gunDatareturn = gunDataTemp[6, mode];
                    return gunDatareturn;

                case "4MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[7, mode];
                    return gunDatareturn;

                case "20MW Particle Laser":
                    gunDatareturn = gunDataTemp[8, mode];
                    return gunDatareturn;

                case "20MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[9, mode];
                    return gunDatareturn;

                case "100MW Particle Laser":
                    gunDatareturn = gunDataTemp[10, mode];
                    return gunDatareturn;

                case "100MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[11, mode];
                    return gunDatareturn;

                case "4MW Gatling Laser":
                    gunDatareturn = gunDataTemp[12, mode];
                    return gunDatareturn;

                case "4MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[13, mode];
                    return gunDatareturn;

                case "6MW Gatling Laser":
                    gunDatareturn = gunDataTemp[14, mode];
                    return gunDatareturn;

                case "6MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[15, mode];
                    return gunDatareturn;

                case "10MW Gatling Laser":
                    gunDatareturn = gunDataTemp[16, mode];
                    return gunDatareturn;

                case "10MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[17, mode];
                    return gunDatareturn;

                case "20MW Gatling Laser":
                    gunDatareturn = gunDataTemp[18, mode];
                    return gunDatareturn;

                case "20MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[19, mode];
                    return gunDatareturn;

                case "35MW Plasma":
                    gunDatareturn = gunDataTemp[20, mode];
                    return gunDatareturn;

                case "40MW Plasma":
                    gunDatareturn = gunDataTemp[21, mode];
                    return gunDatareturn;

                case "60MW Plasma":
                    gunDatareturn = gunDataTemp[22, mode];
                    return gunDatareturn;

                case "140MW Particle Laser":
                    gunDatareturn = gunDataTemp[23, mode];
                    return gunDatareturn;

                case "140MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[24, mode];
                    return gunDatareturn;

                case "Exoplasm Launcher":
                    gunDatareturn = gunDataTemp[25, mode];
                    return gunDatareturn;

                case "Endoplasm Launcher":
                    gunDatareturn = gunDataTemp[26, mode];
                    return gunDatareturn;

                case "Bio-Spore Array":
                    gunDatareturn = gunDataTemp[27, mode];
                    return gunDatareturn;

                case "Viral Glands":
                    gunDatareturn = gunDataTemp[28, mode];
                    return gunDatareturn;

                case "80MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[29, mode];
                    return gunDatareturn;

                case "120MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[30, mode];
                    return gunDatareturn;

                case "Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[31, mode];
                    return gunDatareturn;

                case "Very Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[32, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer I":
                    gunDatareturn = gunDataTemp[33, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer II":
                    gunDatareturn = gunDataTemp[34, mode];
                    return gunDatareturn;

                case "Lucidi Conqueror":
                    gunDatareturn = gunDataTemp[35, mode];
                    return gunDatareturn;

                case "Lucidi Plasma Thrower":
                    gunDatareturn = gunDataTemp[36, mode];
                    return gunDatareturn;
            }
            return 0;
        }

        private int GetGunData2(ref int mode)
        {
            int gunDatareturn;
            int[,] gunDataTemp = GetGunData();

            switch (gunLoadoutComboBox2.Text)
            {
                case ":: None ::":
                case ":: Normal Guns::":
                case ":: Empire Guns ::":
                case "":
                case " ":
                case ":: Organic ::":
                case ":: Electro-Magnetic ::":
                case ":: Pardus ::":
                    gunDatareturn = gunDataTemp[0, mode];
                    return gunDatareturn;

                case "10MW Mining Laser":
                    gunDatareturn = gunDataTemp[1, mode];
                    return gunDatareturn;

                case "30MW Mining Laser":
                    gunDatareturn = gunDataTemp[2, mode];
                    return gunDatareturn;

                case "1MW Impulse Laser":
                    gunDatareturn = gunDataTemp[3, mode];
                    return gunDatareturn;

                case "5MW Impulse Laser":
                    gunDatareturn = gunDataTemp[4, mode];
                    return gunDatareturn;

                case "1MW Particle Laser":
                    gunDatareturn = gunDataTemp[5, mode];
                    return gunDatareturn;

                case "4MW Particle Laser":
                    gunDatareturn = gunDataTemp[6, mode];
                    return gunDatareturn;

                case "4MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[7, mode];
                    return gunDatareturn;

                case "20MW Particle Laser":
                    gunDatareturn = gunDataTemp[8, mode];
                    return gunDatareturn;

                case "20MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[9, mode];
                    return gunDatareturn;

                case "100MW Particle Laser":
                    gunDatareturn = gunDataTemp[10, mode];
                    return gunDatareturn;

                case "100MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[11, mode];
                    return gunDatareturn;

                case "4MW Gatling Laser":
                    gunDatareturn = gunDataTemp[12, mode];
                    return gunDatareturn;

                case "4MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[13, mode];
                    return gunDatareturn;

                case "6MW Gatling Laser":
                    gunDatareturn = gunDataTemp[14, mode];
                    return gunDatareturn;

                case "6MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[15, mode];
                    return gunDatareturn;

                case "10MW Gatling Laser":
                    gunDatareturn = gunDataTemp[16, mode];
                    return gunDatareturn;

                case "10MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[17, mode];
                    return gunDatareturn;

                case "20MW Gatling Laser":
                    gunDatareturn = gunDataTemp[18, mode];
                    return gunDatareturn;

                case "20MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[19, mode];
                    return gunDatareturn;

                case "35MW Plasma":
                    gunDatareturn = gunDataTemp[20, mode];
                    return gunDatareturn;

                case "40MW Plasma":
                    gunDatareturn = gunDataTemp[21, mode];
                    return gunDatareturn;

                case "60MW Plasma":
                    gunDatareturn = gunDataTemp[22, mode];
                    return gunDatareturn;

                case "140MW Particle Laser":
                    gunDatareturn = gunDataTemp[23, mode];
                    return gunDatareturn;

                case "140MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[24, mode];
                    return gunDatareturn;

                case "Exoplasm Launcher":
                    gunDatareturn = gunDataTemp[25, mode];
                    return gunDatareturn;

                case "Endoplasm Launcher":
                    gunDatareturn = gunDataTemp[26, mode];
                    return gunDatareturn;

                case "Bio-Spore Array":
                    gunDatareturn = gunDataTemp[27, mode];
                    return gunDatareturn;

                case "Viral Glands":
                    gunDatareturn = gunDataTemp[28, mode];
                    return gunDatareturn;

                case "80MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[29, mode];
                    return gunDatareturn;

                case "120MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[30, mode];
                    return gunDatareturn;

                case "Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[31, mode];
                    return gunDatareturn;

                case "Very Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[32, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer I":
                    gunDatareturn = gunDataTemp[33, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer II":
                    gunDatareturn = gunDataTemp[34, mode];
                    return gunDatareturn;

                case "Lucidi Conqueror":
                    gunDatareturn = gunDataTemp[35, mode];
                    return gunDatareturn;

                case "Lucidi Plasma Thrower":
                    gunDatareturn = gunDataTemp[36, mode];
                    return gunDatareturn;
            }
            return 0;
        }

        private int GetGunData3(ref int mode)
        {
            int gunDatareturn;
            int[,] gunDataTemp = GetGunData();

            switch (gunLoadoutComboBox3.Text)
            {
                case ":: None ::":
                case ":: Normal Guns::":
                case ":: Empire Guns ::":
                case "":
                case " ":
                case ":: Organic ::":
                case ":: Electro-Magnetic ::":
                case ":: Pardus ::":
                    gunDatareturn = gunDataTemp[0, mode];
                    return gunDatareturn;

                case "10MW Mining Laser":
                    gunDatareturn = gunDataTemp[1, mode];
                    return gunDatareturn;

                case "30MW Mining Laser":
                    gunDatareturn = gunDataTemp[2, mode];
                    return gunDatareturn;

                case "1MW Impulse Laser":
                    gunDatareturn = gunDataTemp[3, mode];
                    return gunDatareturn;

                case "5MW Impulse Laser":
                    gunDatareturn = gunDataTemp[4, mode];
                    return gunDatareturn;

                case "1MW Particle Laser":
                    gunDatareturn = gunDataTemp[5, mode];
                    return gunDatareturn;

                case "4MW Particle Laser":
                    gunDatareturn = gunDataTemp[6, mode];
                    return gunDatareturn;

                case "4MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[7, mode];
                    return gunDatareturn;

                case "20MW Particle Laser":
                    gunDatareturn = gunDataTemp[8, mode];
                    return gunDatareturn;

                case "20MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[9, mode];
                    return gunDatareturn;

                case "100MW Particle Laser":
                    gunDatareturn = gunDataTemp[10, mode];
                    return gunDatareturn;

                case "100MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[11, mode];
                    return gunDatareturn;

                case "4MW Gatling Laser":
                    gunDatareturn = gunDataTemp[12, mode];
                    return gunDatareturn;

                case "4MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[13, mode];
                    return gunDatareturn;

                case "6MW Gatling Laser":
                    gunDatareturn = gunDataTemp[14, mode];
                    return gunDatareturn;

                case "6MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[15, mode];
                    return gunDatareturn;

                case "10MW Gatling Laser":
                    gunDatareturn = gunDataTemp[16, mode];
                    return gunDatareturn;

                case "10MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[17, mode];
                    return gunDatareturn;

                case "20MW Gatling Laser":
                    gunDatareturn = gunDataTemp[18, mode];
                    return gunDatareturn;

                case "20MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[19, mode];
                    return gunDatareturn;

                case "35MW Plasma":
                    gunDatareturn = gunDataTemp[20, mode];
                    return gunDatareturn;

                case "40MW Plasma":
                    gunDatareturn = gunDataTemp[21, mode];
                    return gunDatareturn;

                case "60MW Plasma":
                    gunDatareturn = gunDataTemp[22, mode];
                    return gunDatareturn;

                case "140MW Particle Laser":
                    gunDatareturn = gunDataTemp[23, mode];
                    return gunDatareturn;

                case "140MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[24, mode];
                    return gunDatareturn;

                case "Exoplasm Launcher":
                    gunDatareturn = gunDataTemp[25, mode];
                    return gunDatareturn;

                case "Endoplasm Launcher":
                    gunDatareturn = gunDataTemp[26, mode];
                    return gunDatareturn;

                case "Bio-Spore Array":
                    gunDatareturn = gunDataTemp[27, mode];
                    return gunDatareturn;

                case "Viral Glands":
                    gunDatareturn = gunDataTemp[28, mode];
                    return gunDatareturn;

                case "80MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[29, mode];
                    return gunDatareturn;

                case "120MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[30, mode];
                    return gunDatareturn;

                case "Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[31, mode];
                    return gunDatareturn;

                case "Very Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[32, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer I":
                    gunDatareturn = gunDataTemp[33, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer II":
                    gunDatareturn = gunDataTemp[34, mode];
                    return gunDatareturn;

                case "Lucidi Conqueror":
                    gunDatareturn = gunDataTemp[35, mode];
                    return gunDatareturn;

                case "Lucidi Plasma Thrower":
                    gunDatareturn = gunDataTemp[36, mode];
                    return gunDatareturn;
            }
            return 0;
        }

        private int GetGunData4(ref int mode)
        {
            int gunDatareturn;
            int[,] gunDataTemp = GetGunData();

            switch (gunLoadoutComboBox4.Text)
            {
                case ":: None ::":
                case ":: Normal Guns::":
                case ":: Empire Guns ::":
                case "":
                case " ":
                case ":: Organic ::":
                case ":: Electro-Magnetic ::":
                case ":: Pardus ::":
                    gunDatareturn = gunDataTemp[0, mode];
                    return gunDatareturn;

                case "10MW Mining Laser":
                    gunDatareturn = gunDataTemp[1, mode];
                    return gunDatareturn;

                case "30MW Mining Laser":
                    gunDatareturn = gunDataTemp[2, mode];
                    return gunDatareturn;

                case "1MW Impulse Laser":
                    gunDatareturn = gunDataTemp[3, mode];
                    return gunDatareturn;

                case "5MW Impulse Laser":
                    gunDatareturn = gunDataTemp[4, mode];
                    return gunDatareturn;

                case "1MW Particle Laser":
                    gunDatareturn = gunDataTemp[5, mode];
                    return gunDatareturn;

                case "4MW Particle Laser":
                    gunDatareturn = gunDataTemp[6, mode];
                    return gunDatareturn;

                case "4MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[7, mode];
                    return gunDatareturn;

                case "20MW Particle Laser":
                    gunDatareturn = gunDataTemp[8, mode];
                    return gunDatareturn;

                case "20MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[9, mode];
                    return gunDatareturn;

                case "100MW Particle Laser":
                    gunDatareturn = gunDataTemp[10, mode];
                    return gunDatareturn;

                case "100MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[11, mode];
                    return gunDatareturn;

                case "4MW Gatling Laser":
                    gunDatareturn = gunDataTemp[12, mode];
                    return gunDatareturn;

                case "4MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[13, mode];
                    return gunDatareturn;

                case "6MW Gatling Laser":
                    gunDatareturn = gunDataTemp[14, mode];
                    return gunDatareturn;

                case "6MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[15, mode];
                    return gunDatareturn;

                case "10MW Gatling Laser":
                    gunDatareturn = gunDataTemp[16, mode];
                    return gunDatareturn;

                case "10MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[17, mode];
                    return gunDatareturn;

                case "20MW Gatling Laser":
                    gunDatareturn = gunDataTemp[18, mode];
                    return gunDatareturn;

                case "20MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[19, mode];
                    return gunDatareturn;

                case "35MW Plasma":
                    gunDatareturn = gunDataTemp[20, mode];
                    return gunDatareturn;

                case "40MW Plasma":
                    gunDatareturn = gunDataTemp[21, mode];
                    return gunDatareturn;

                case "60MW Plasma":
                    gunDatareturn = gunDataTemp[22, mode];
                    return gunDatareturn;

                case "140MW Particle Laser":
                    gunDatareturn = gunDataTemp[23, mode];
                    return gunDatareturn;

                case "140MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[24, mode];
                    return gunDatareturn;

                case "Exoplasm Launcher":
                    gunDatareturn = gunDataTemp[25, mode];
                    return gunDatareturn;

                case "Endoplasm Launcher":
                    gunDatareturn = gunDataTemp[26, mode];
                    return gunDatareturn;

                case "Bio-Spore Array":
                    gunDatareturn = gunDataTemp[27, mode];
                    return gunDatareturn;

                case "Viral Glands":
                    gunDatareturn = gunDataTemp[28, mode];
                    return gunDatareturn;

                case "80MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[29, mode];
                    return gunDatareturn;

                case "120MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[30, mode];
                    return gunDatareturn;

                case "Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[31, mode];
                    return gunDatareturn;

                case "Very Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[32, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer I":
                    gunDatareturn = gunDataTemp[33, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer II":
                    gunDatareturn = gunDataTemp[34, mode];
                    return gunDatareturn;

                case "Lucidi Conqueror":
                    gunDatareturn = gunDataTemp[35, mode];
                    return gunDatareturn;

                case "Lucidi Plasma Thrower":
                    gunDatareturn = gunDataTemp[36, mode];
                    return gunDatareturn;
            }
            return 0;
        }

        private int GetGunData5(ref int mode)
        {
            int gunDatareturn;
            int[,] gunDataTemp = GetGunData();

            switch (gunLoadoutComboBox5.Text)
            {
                case ":: None ::":
                case ":: Normal Guns::":
                case ":: Empire Guns ::":
                case "":
                case " ":
                case ":: Organic ::":
                case ":: Electro-Magnetic ::":
                case ":: Pardus ::":
                    gunDatareturn = gunDataTemp[0, mode];
                    return gunDatareturn;

                case "10MW Mining Laser":
                    gunDatareturn = gunDataTemp[1, mode];
                    return gunDatareturn;

                case "30MW Mining Laser":
                    gunDatareturn = gunDataTemp[2, mode];
                    return gunDatareturn;

                case "1MW Impulse Laser":
                    gunDatareturn = gunDataTemp[3, mode];
                    return gunDatareturn;

                case "5MW Impulse Laser":
                    gunDatareturn = gunDataTemp[4, mode];
                    return gunDatareturn;

                case "1MW Particle Laser":
                    gunDatareturn = gunDataTemp[5, mode];
                    return gunDatareturn;

                case "4MW Particle Laser":
                    gunDatareturn = gunDataTemp[6, mode];
                    return gunDatareturn;

                case "4MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[7, mode];
                    return gunDatareturn;

                case "20MW Particle Laser":
                    gunDatareturn = gunDataTemp[8, mode];
                    return gunDatareturn;

                case "20MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[9, mode];
                    return gunDatareturn;

                case "100MW Particle Laser":
                    gunDatareturn = gunDataTemp[10, mode];
                    return gunDatareturn;

                case "100MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[11, mode];
                    return gunDatareturn;

                case "4MW Gatling Laser":
                    gunDatareturn = gunDataTemp[12, mode];
                    return gunDatareturn;

                case "4MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[13, mode];
                    return gunDatareturn;

                case "6MW Gatling Laser":
                    gunDatareturn = gunDataTemp[14, mode];
                    return gunDatareturn;

                case "6MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[15, mode];
                    return gunDatareturn;

                case "10MW Gatling Laser":
                    gunDatareturn = gunDataTemp[16, mode];
                    return gunDatareturn;

                case "10MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[17, mode];
                    return gunDatareturn;

                case "20MW Gatling Laser":
                    gunDatareturn = gunDataTemp[18, mode];
                    return gunDatareturn;

                case "20MW LW Gatling Laser":
                    gunDatareturn = gunDataTemp[19, mode];
                    return gunDatareturn;

                case "35MW Plasma":
                    gunDatareturn = gunDataTemp[20, mode];
                    return gunDatareturn;

                case "40MW Plasma":
                    gunDatareturn = gunDataTemp[21, mode];
                    return gunDatareturn;

                case "60MW Plasma":
                    gunDatareturn = gunDataTemp[22, mode];
                    return gunDatareturn;

                case "140MW Particle Laser":
                    gunDatareturn = gunDataTemp[23, mode];
                    return gunDatareturn;

                case "140MW LW Particle Laser":
                    gunDatareturn = gunDataTemp[24, mode];
                    return gunDatareturn;

                case "Exoplasm Launcher":
                    gunDatareturn = gunDataTemp[25, mode];
                    return gunDatareturn;

                case "Endoplasm Launcher":
                    gunDatareturn = gunDataTemp[26, mode];
                    return gunDatareturn;

                case "Bio-Spore Array":
                    gunDatareturn = gunDataTemp[27, mode];
                    return gunDatareturn;

                case "Viral Glands":
                    gunDatareturn = gunDataTemp[28, mode];
                    return gunDatareturn;

                case "80MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[29, mode];
                    return gunDatareturn;

                case "120MT Magnetic Defractor":
                    gunDatareturn = gunDataTemp[30, mode];
                    return gunDatareturn;

                case "Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[31, mode];
                    return gunDatareturn;

                case "Very Large Pulse Cannon":
                    gunDatareturn = gunDataTemp[32, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer I":
                    gunDatareturn = gunDataTemp[33, mode];
                    return gunDatareturn;

                case "Lucidi Enforcer II":
                    gunDatareturn = gunDataTemp[34, mode];
                    return gunDatareturn;

                case "Lucidi Conqueror":
                    gunDatareturn = gunDataTemp[35, mode];
                    return gunDatareturn;

                case "Lucidi Plasma Thrower":
                    gunDatareturn = gunDataTemp[36, mode];
                    return gunDatareturn;
            }
            return 0;
        } // End of Gun lookup tables.

        // Ask for new data from lookup on user request & update displayed data
        private void gunLoadoutComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gunLoadoutComboBox1.Enabled == true)
            {
                UpdateGun1();
            }
            aggregateGunDamage();
            aggregateGunCost();
            freeSpaceRequiredForGuns();
        }

        private void gunLoadoutComboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gunLoadoutComboBox2.Enabled == true)
            {
                UpdateGun2();
            }
            aggregateGunDamage();
            aggregateGunCost();
            freeSpaceRequiredForGuns();
        }

        private void gunLoadoutComboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gunLoadoutComboBox3.Enabled == true)
            {
                UpdateGun3();
            }
            aggregateGunDamage();
            aggregateGunCost();
            freeSpaceRequiredForGuns();
        }

        private void gunLoadoutComboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gunLoadoutComboBox4.Enabled == true)
            {
                UpdateGun4();
            }
            aggregateGunDamage();
            aggregateGunCost();
            freeSpaceRequiredForGuns();
        }

        private void gunLoadoutComboBox5_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gunLoadoutComboBox5.Enabled == true)
            {
                UpdateGun5();
            }
            aggregateGunDamage();
            aggregateGunCost();
            freeSpaceRequiredForGuns();
        }

        private void UpdateGun1()
        {
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            int modeCost = 3;

            gunDamageLabel1.Text = GetGunData1(ref modeDamage).ToString();
            gunFireRateLabel1.Text = GetGunData1(ref modeFireRate).ToString();
            gunWeightLabel1.Text = GetGunData1(ref modeWeight).ToString();
            gunCostLabel1.Text = GetGunData1(ref modeCost).ToString("N0");
            totalGunDamageLabel1.Text = ((GetGunData1(ref modeDamage) * (GetGunData1(ref modeFireRate)))).ToString();
        }

        private void UpdateGun2()
        {
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            int modeCost = 3;

            gunDamageLabel2.Text = GetGunData2(ref modeDamage).ToString();
            gunFireRateLabel2.Text = GetGunData2(ref modeFireRate).ToString();
            gunWeightLabel2.Text = GetGunData2(ref modeWeight).ToString();
            gunCostLabel2.Text = GetGunData2(ref modeCost).ToString("N0");
            totalGunDamageLabel2.Text = ((GetGunData2(ref modeDamage) * (GetGunData2(ref modeFireRate)))).ToString();
        }

        private void UpdateGun3()
        {
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            int modeCost = 3;

            gunDamageLabel3.Text = GetGunData3(ref modeDamage).ToString();
            gunFireRateLabel3.Text = GetGunData3(ref modeFireRate).ToString();
            gunWeightLabel3.Text = GetGunData3(ref modeWeight).ToString();
            gunCostLabel3.Text = GetGunData3(ref modeCost).ToString("N0");
            totalGunDamageLabel3.Text = ((GetGunData3(ref modeDamage) * (GetGunData3(ref modeFireRate)))).ToString();
        }

        private void UpdateGun4()
        {
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            int modeCost = 3;

            gunDamageLabel4.Text = GetGunData4(ref modeDamage).ToString();
            gunFireRateLabel4.Text = GetGunData4(ref modeFireRate).ToString();
            gunWeightLabel4.Text = GetGunData4(ref modeWeight).ToString();
            gunCostLabel4.Text = GetGunData4(ref modeCost).ToString("N0");
            totalGunDamageLabel4.Text = ((GetGunData4(ref modeDamage) * (GetGunData4(ref modeFireRate)))).ToString();
        }

        private void UpdateGun5()
        {
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            int modeCost = 3;

            gunDamageLabel5.Text = GetGunData5(ref modeDamage).ToString();
            gunFireRateLabel5.Text = GetGunData5(ref modeFireRate).ToString();
            gunWeightLabel5.Text = GetGunData5(ref modeWeight).ToString();
            gunCostLabel5.Text = GetGunData5(ref modeCost).ToString("N0");
            totalGunDamageLabel5.Text = ((GetGunData5(ref modeDamage) * (GetGunData5(ref modeFireRate)))).ToString();
        } // End of all those functions called when the gun selection box event handlers are set off.

        // Calculates overall base gun damage.
        private void aggregateGunDamage()
        {
            aggregateDamageLabel.Text = ((int.Parse(totalGunDamageLabel1.Text)) + (int.Parse(totalGunDamageLabel2.Text)) + (int.Parse(totalGunDamageLabel3.Text)) + (int.Parse(totalGunDamageLabel4.Text)) + (int.Parse(totalGunDamageLabel5.Text))).ToString("N0");
        }

        private void aggregateGunCost()
        {
            string comma = ",";
            string nothing = "";
            int gunCost1;
            int gunCost2;
            int gunCost3;
            int gunCost4;
            int gunCost5;

            gunCost1 = int.Parse(gunCostLabel1.Text.Replace(comma, nothing));
            gunCost2 = int.Parse(gunCostLabel2.Text.Replace(comma, nothing));
            gunCost3 = int.Parse(gunCostLabel3.Text.Replace(comma, nothing));
            gunCost4 = int.Parse(gunCostLabel4.Text.Replace(comma, nothing));
            gunCost5 = int.Parse(gunCostLabel5.Text.Replace(comma, nothing));

            totalGunCostLabel.Text = ((gunCost1) + (gunCost2) + (gunCost3) + (gunCost4) + (gunCost5)).ToString("N0");
        }

        private void freeSpaceRequiredForGuns()
        {
            totalFreeSpaceRequiredLabel.Text = ((int.Parse(gunWeightLabel1.Text)) + (int.Parse(gunWeightLabel2.Text)) + (int.Parse(gunWeightLabel3.Text)) + (int.Parse(gunWeightLabel4.Text)) + (int.Parse(gunWeightLabel5.Text))).ToString();
        }

        // Manage fancy bars option from options tab.
        private void enableFancyBarsCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (enableFancyBarsCheckBox.Checked == true)
            {
                trackBar1.Enabled = true;
                MessageBox.Show("WARNING: The fancy bars shouldn't cause any major crashes anymore - HOWEVER. They are incredibly slow, and don't seem to work with ships hull/armor over 600 points.", "WARNING!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            if (enableFancyBarsCheckBox.Checked == false)
            {
                trackBar1.Enabled = false;
                FancyBars = false;
            }
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            if (trackBar1.Value == 1)
            {
                FancyBars = true;
            }
            if (trackBar1.Value != 1)
            {
                FancyBars = false;
            }
        } // End of fancy bars management from options tab code.
    }
}
